/*-------------------------------------------------------------------------*/
/**
  @file		execrefine_gain.c
  @author	Renaud Wanchoor
  @date	July 2004
  @version	$Revision: 2.26 $
  @brief	main program
  
*/
/*--------------------------------------------------------------------------*/

#include "pagrid.h"

int main(int argc, char *argv[]){
  GraphType	*graph;
  GridType	*grid;
  PartInfoType	info;

  IoCtrl ioctrl;

  int Iodef[IO_DEF];
  int Ioptdef[IO_DEF];
  int Ioaut[IO_DEF];

#ifdef DEBUG
  dbg_freemem();
#endif
  
  info.rtimer[0] = gettimes();  
  
  /* default values */
  Iodef[IO_DMATCH] 	= IO_MATCH_SHEM;
  Iodef[IO_DWEIGHT]	= IO_WEIGHT_NORM;
  Iodef[IO_DUNCO]	= IO_UNCO_KLEXEC;
  Iodef[IO_DSER]	= IO_SER_NONE;
  Iodef[IO_DRAND] 	= IO_RAND_NONE;
  Iodef[IO_DOUT] 	= IO_OUT_NOLEVEL;
  Iodef[IO_DBGLVL] 	= 0;
  	
  Ioptdef[IO_DMATCH] 	= IO_MATCH_MWM;
  Ioptdef[IO_DWEIGHT] 	= IO_WEIGHT_UPGMA;
  Ioptdef[IO_DUNCO] 	= IO_UNCO_KLEXEC;
  Ioptdef[IO_DSER] 	= IO_SER_DO;
  Ioptdef[IO_DRAND] 	= IO_RAND_ALL;
  Ioptdef[IO_DOUT] 	= IO_OUT_LEVEL;
  Ioptdef[IO_DBGLVL] 	= 1;  
  
	/* authorized options */
  Ioaut[IO_DMATCH] 	= 775;
  Ioaut[IO_DWEIGHT]	= 3;
  Ioaut[IO_DUNCO]	= 4;
  Ioaut[IO_DOUT]	= 7;
  Ioaut[IO_DSER] 	= 7;
  Ioaut[IO_DRAND] 	= 15;
  
  /* get args */
  IO_args(argc, argv,Iodef,Ioptdef,Ioaut,"cCkKmoOrRsSuUwG",&ioctrl);

  info.WType  = ioctrl.WType;
  info.CType  = ioctrl.CType;
  info.RType  = ioctrl.RType;
  info.out[0] = ioctrl.out[0];
  info.out[1] = ioctrl.out[1];
  info.out[2] = ioctrl.out[2];
  info.PSeed  = ioctrl.PSeed;
  info.CSeed  = ioctrl.CSeed;
  info.ISeed  = ioctrl.ISeed;
  info.RSeed  = ioctrl.RSeed;
  info.NBytes = ioctrl.NBytes;
  strcpy(info.F_output,ioctrl.F_output);
  info.F_graph = ioctrl.F_graph;
  info.F_grid  = ioctrl.F_grid;
  strcpy(info.F_serialize,ioctrl.F_serialize);  
  
  /*info.PSeed = 1987592569;
  info.CSeed = 990126827;
  info.ISeed = 1547088743;
  info.RSeed = 1457621179;*/
  
  /* imbalance */
  /*info.PSeed = 2101606990;
  info.CSeed = 418161170;
  info.ISeed = 1074941239;
  info.RSeed = 409259603;*/
  

//  printf("Random Seeds : \n");
//  printf("--------------\n");
//  fprintf(stdout/*stderr*/," The startseed         = %d\n",info.PSeed);
//  fprintf(stdout/*stderr*/," The matchseed         = %d\n",info.CSeed);
//  fprintf(stdout/*stderr*/," The inipartitionseed  = %d\n",info.ISeed);
//  fprintf(stdout/*stderr*/," The refineseed        = %d\n",info.RSeed);  

//  printf("\nLets go:\n");
//  printf("--------\n");

  /*Get Data*/
  readfiles(&graph,info.F_graph,&grid,info.F_grid, info.NBytes);
    
  /* partitionning */
  MultiLevelPartition(graph, grid, &info);
  
  /* output */
  IO_write(TOOL_PAGRID,graph, grid,
	   info.F_output,info.out[IO_RESULT],info.out[IO_ID]);
  IO_writeLog(TOOL_PAGRID,graph, grid, 0,
	      info.CType, info.WType, info.RType,
	      info.CSeed, -1, info.RSeed,
	      info.F_graph,info.F_grid,info.F_output, info.F_serialize,
	      info.out[IO_ID],
	      info.cputime[1], info.cputime[2], info.cputime[3],
	      info.cputime[4], info.cputime[0]);

  LIBG_Free(graph);
  LIBN_Free(grid);

#ifdef DEBUG
  dbg_isemptymem();
#endif
  
  return 0;
}
